package com.appspot.zcmjqm.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.appspot.zcmjqm.app.model.quote.ServiceQuote;
import com.appspot.zcmjqm.service.ServiceService;

@Controller
@RequestMapping("/service")
public class ServiceControllerWebMVCImpl implements ServiceController {
	
	@Autowired
	private ServiceService serviceService;

	@RequestMapping("/display.do")
	public ModelAndView displayService(@RequestParam String serviceKey) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("service", serviceService.getById(serviceKey));
		mav.setViewName("service");
		return mav;
	}

	@RequestMapping("/list.do")
	public ModelAndView displayServices(@RequestParam String categoryKey) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("services", serviceService.getByCategory(categoryKey));
		mav.setViewName("services");
		return mav;
	}
	
	@RequestMapping("/dispalyquote.do")
	public ModelAndView displayQuote(@RequestParam String serviceKey) {
		ModelAndView mav = new ModelAndView();
		ServiceQuote serviceQuote = new ServiceQuote();
		mav.addObject("serviceQuote", serviceQuote);
		mav.setViewName("serviceQuote");
		return mav;
	}
	
	@RequestMapping("/quote.do")
	public ModelAndView newServiceQuote(ServiceQuote serviceQuote) {
		ModelAndView mav = new ModelAndView();
		serviceService.saveQuote(serviceQuote);
		mav.setViewName("redirect:/home/show.do");
		return mav;
	}

	public void setServiceService(ServiceService serviceService) {
		this.serviceService = serviceService;
	}

}